package com.achen.controller;

import com.achen.elasticsearch.dao.EmpRepository;
import com.achen.elasticsearch.pojo.Emp;
import com.achen.entity.Result;
import com.achen.pojo.User;
import com.achen.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author limeng
 * @create 2021-05-21 13:49
 */
@RestController
@Slf4j
public class UserController {

    @Autowired
    private EmpRepository empRepository;

    @Autowired
    private UserService userService;

    @Value("${env_name}")
    private String env_name;

    @GetMapping("/test")
    public String test() {
        log.info("env_name:[{}]", env_name);
        return "hello";
    }

    @GetMapping("/emp/findAll")
    public Result findAll() {

        Iterable<Emp> all = empRepository.findAll();
        return new Result(all, 200, "查询成功");
    }

    @GetMapping("/user/findAll")
    public Result findAll2() {

        List<User> all = userService.findAll();
        return new Result(all, 200, "查询成功");
    }


}
